package com.sr.examination.wxapi;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.sr.examination.R;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.tl.commonlibrary.event.EventUtil;
import com.tl.commonlibrary.tool.Logger;
import com.tl.commonlibrary.ui.BaseFragmentActivity;
import com.tl.libpay.ui.WXPayEvent;
import com.tl.libpay.wx.Constants;

/**
 * Created by Administrator on 2017/9/6.
 */

public class WXPayEntryActivity extends BaseFragmentActivity implements IWXAPIEventHandler {

    private IWXAPI api;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTheme(R.style.Transparent);
        api = WXAPIFactory.createWXAPI(this, Constants.APP_ID);
        api.handleIntent(getIntent(), this);

    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onClick(View v) {

    }


    @Override
    public void onReq(BaseReq baseReq) {

    }

    @Override
    public void onResp(BaseResp resp) {
        Logger.i("errcode",resp.errCode+"");
        String message="";
        if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX&&resp.errCode==0) {
            message=getString(R.string.pay_success);
        }else if (resp.errCode==-1){
            message=getString(R.string.pay_failed);
        }else {
          message=getString(R.string.pay_canceled);
        }
        EventUtil.post(new WXPayEvent(resp.errCode+"",message));
        finish();

    }


    @Override
    public void onFragmentTrigger(int tag, Bundle bundle) {

    }



}
